package com.ling.sdk.services

import android.content.Context
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.facade.service.SerializationService
import com.google.gson.Gson
import java.lang.reflect.Type

/**
 * Created by MinF on 2018/8/1 0001.
 */
@Route(path = "/service/json")
class RouterJsonService : SerializationService {
    private val gson = Gson()
    override fun <T : Any?> json2Object(input: String?, clazz: Class<T>?) = null

    override fun init(context: Context?) {
    }

    override fun object2Json(instance: Any?): String? {
        instance?.also {
            return gson.toJson(instance)
        }
        return null
    }

    override fun <T : Any?> parseObject(input: String?, clazz: Type?): T? {
        if (input == null) return null
        return gson.fromJson(input,clazz)
    }

}